package cn.swing.ushare.element.webapi.controller;

import cn.swing.ushare.common.web.JsonResult;
import cn.swing.ushare.element.service.IElementService;
import cn.swing.ushare.pojo.dto.CarouselDTO;
import cn.swing.ushare.pojo.dto.MenuBarDTO;
import cn.swing.ushare.pojo.vo.CarouselVO;
import cn.swing.ushare.pojo.vo.MenuBarVO;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/elements", produces = "application/json;charset=utf-8")
public class ElementController {

    @Autowired
    private IElementService elementService;

    @GetMapping("/listCarousel")
//    @PreAuthorize("hasAnyAuthority('轮播图管理')")
    public JsonResult<List<CarouselVO>> list() {
        List<CarouselVO> list = elementService.list();
        return JsonResult.ok(list);
    }
    @PostMapping("/updateCarousel")
    @PreAuthorize("hasAnyAuthority('轮播图管理')")
    public JsonResult<Integer> updateCarousel(@RequestBody CarouselVO carousel){
        Integer result = elementService.updateCarousel(carousel);
        return JsonResult.ok(result);
    }

    @PostMapping("/deleteCarousel")
    @PreAuthorize("hasAnyAuthority('轮播图管理')")
    public JsonResult<Integer> deleteCarousel(Integer id) {
        Integer result = elementService.deleteCarousel(id);
        return JsonResult.ok(result);
    }

    @PostMapping("/insertCarousel")
    @PreAuthorize("hasAnyAuthority('轮播图管理')")
    public JsonResult<Integer> insertCarousel(@RequestBody CarouselDTO carousel) {
        Integer result = elementService.insertCarousel(carousel);
        return JsonResult.ok(result);
    }

    @GetMapping("/listMenuBar")
//    @PreAuthorize("hasAnyAuthority('导航栏管理')")
    public JsonResult<List<MenuBarVO>> listMenuBar() {
        List<MenuBarVO> list = elementService.listMenuBar();
        return JsonResult.ok(list);
    }

    @PostMapping("/updateMenuBar")
    @PreAuthorize("hasAnyAuthority('导航栏管理')")
    public JsonResult<Integer> updateMenuBar(@RequestBody MenuBarDTO menuBar){
        Integer result = elementService.updateMenuBar(menuBar);
        return JsonResult.ok(result);
    }

    @PostMapping("/deleteMenuBar")
    @PreAuthorize("hasAnyAuthority('导航栏管理')")
    public JsonResult<Integer> deleteMenuBar(Integer id) {
        Integer result = elementService.deleteMenuBar(id);
        return JsonResult.ok(result);
    }

    @PostMapping("/insertMenuBar")
    @PreAuthorize("hasAnyAuthority('导航栏管理')")
    public JsonResult<Integer> insertMenuBar(@RequestBody MenuBarDTO menuBar) {
        Integer result = elementService.insertMenuBar(menuBar);
        return JsonResult.ok(result);
    }
}
